/*
 *  Virus.cpp
 *  
 *
 *  Created by Daniel Condon on 20/09/12.
 *  Copyright 2012 __MyCompanyName__. All rights reserved.
 *
 */

#include <stdio.h>
#include <stdlib.h>
#include <iostream>

#include "Virus.h"

using namespace std;

const double resist = 0.2;

const int ttd = 1000;

Virus::Virus(){
	health = SUSCEPTABLE;
	virusActive = false;
	resistChance = resist;
	ticks = 0;
}

void Virus::activateVirus(){
	if(health == SUSCEPTABLE){
		virusActive = true;
		health = INFECTED;
	}
}

int Virus::hostStatus(){
	return (int)health;
}

bool Virus::canInfect(){
	if (health != INFECTED) {
		return false;
	}
	return true;
}

void Virus::infect(){
	if (health == SUSCEPTABLE) {
		double chance = (double)rand()/(double)RAND_MAX;
		cout << chance << endl;
		if (chance <= resist) {
			health = RESISTANT;
		}else {
			health = INFECTED;
		}
	}
	virusActive = true;
}

bool Virus::Tick(){
	if (virusActive) {
		ticks++;
		if (ticks >= ttd) {
			return true;
		}
	}
	return false;
}

int Virus::getTTD(){
	if (health == RESISTANT) {
		return 0;
	}
	return ticks;
}